<template>
	<div class="oe-toptip">
		<span class="oe-toptip-left">
			<span class="oe-toptip-split">
				<a-breadcrumb separator=">" style="display:inline-block;">
					<a-breadcrumb-item class="oe-toptip-title" v-for="item in breadNewList" :key="item.name">
						<router-link :to="item.path">
							{{ processBread(item.name) }}
						</router-link>
					</a-breadcrumb-item>
				</a-breadcrumb>
				<span class="oe-toptip-list" v-if="examData.paperList.length || examData.repairList.length">
					<a-select :defaultValue="examData.defaultValue" @change="handleChange">
						<a-select-option :value="i" v-for="(i, index) in examData.paperList" :key="i">试卷A{{ index + 1 }}</a-select-option>
						>
						<a-select-option :value="`-${j}`" v-for="(j, index) in examData.repairList" :key="j">试卷B{{ index + 1 }}</a-select-option>
					</a-select>
				</span>
			</span>
		</span>
		<span class="oe-toptip-right" @click="backAction" v-if="showBack">
			<span class="iconfont icon-fanhui"></span>
			<span class="oe-toptip-text">返回</span>
		</span>
	</div>
</template>

<script>
import GetOperationList from '@/lib/mixin/methods.js';
export default {
	name: 'topTip',
	mixins: [GetOperationList],
	data() {
		return {
			breadNameList: {
				examList: '批次(考试)管理',
				examManagement: '考试管理',
				pushExam: '发布考试',
				addExam: '新增试卷',
				addExamOne: '新增考试',
				editExamOne: '编辑考试',
				addExamTwo: '新增考试',
				editExamTwo: '编辑考试',
				stuCard: '准考证',
				stuTickets: '准考证导出',
				reviewPaper: '预览试卷',
				roomManagement: '设置考场',
				examAnalysis: '考试分析',
				dataAnalysis: '数据统计',
				cutScreenDetails: '切屏数据详情',
				questionTypeAnalysis: '题型统计',
				wrongStuList: '错题统计',
				studentExamDetailOne: '学生试卷详情',
				studentExamDetail: '学生试卷详情',
				studentExamDetail2: '学生试卷详情',
				studentExamDetail3: '学生试卷详情',
				studentExamDetail4: '学生试卷详情',
				editExam: '编辑试卷',
				studentManage: '补考考生管理',
				proctorTeacher: '监考教师',
				reviewTeacher: '批阅教师',
				testPaper: '设置试卷',
				notApprovaledList: '未批阅',
				unsubmittedList: '未交',
				approvaledList: '已批阅',
				proctorManage: '监考详情',
				proctorManageOne: '监考详情',
				schoolManagement: '学校管理',
				facultyManagement: '院系管理',
				majorManagement: '专业管理',
				gradeManagement: '年级管理',
				classManagement: '班级管理',
				teacherManagement: '教师管理',
				studentManagement: '学生管理',
				roleManagement: '角色管理',
				menuRole: '菜单角色管理',
				memManagement: '成员管理',
				carteManagement: '菜单管理',
				questionManagement: '题库管理',
				addQuestion: '题目',
				newQuestion: '新建题目',
				editQuestion: '编辑题目',
				recycleBin: '回收站',
				categoryManagement: '分类管理',
				examRoomManagement: '考场管理',
				ruleManage: '出卷规则',
				ruleAdd: '新增规则',
				ruleLook: '查看规则',
				approvalPaper: '批阅试卷',
				approvalManagement: '批阅管理',
				markedPaper: '已批试卷',
				invigilateManagement: '监考管理',
				examWord: '试卷导出',
				examWord1: '试卷导出',
				examWord2: '试卷导出',
				todayExam: '考试概况',
				examStep: '一键设置考试',
				examMonitorStu: '监考学生',
				examMonitorStuOne: '监考学生',
				ruleEdit: '编辑规则',
				stuWordHtml: '学生试卷导出',
				stuWordHtmlOne: '学生试卷导出',
				stuWordHtml2: '学生试卷导出',
				stuWordHtml3: '学生试卷导出',
				stuWordHtml4: '学生试卷导出',
			},
			firstRoter: '',
			secondRouter: '',
		};
	},
	props: {
		// 路由title
		title: {
			type: [String, Array],
			default() {
				return [
					{
						params: {},
						router: '',
						text: '新增考试',
						color: '#262626',
					},
				];
			},
		},
		// 试卷份数量
		examData: {
			type: [Object, Array],
			default() {
				return {
					defaultValue: '',
					paperList: [],
					repairList: [],
				};
			},
		},
		showBack: {
			type: Boolean,
			default: true,
		},
		batchid: {
			type: String,
			default: '',
		},
		batchTitle: {
			type: String,
			default: '',
		},
		examTitle: {
			type: String,
			default: '',
		},
		roleId: {
			type: String,
			default: '',
		},
		courseTitle: {
			type: String,
			default: '',
		},
		teacherName: {
			type: String,
			default: '',
		},
	},
	computed: {
		breadNewList() {
			console.log(this.$route.meta.bread);
			let bread = this.$route.meta.bread.map((item) => {
				return {
					...item,
					path: item.path
						.replace(':batchid', this.$route.params.batchid)
						.replace(':examid', this.$route.params.examid)
						.replace(':paperType', this.$route.params.paperType)
						.replace(':examType', this.$route.params.examType)
						.replace(':addid', this.$route.params.addid)
						.replace(':teacherkey', this.$route.params.teacherkey)
						.replace(':examid', this.$route.params.examid)
						.replace(':stuid', this.$route.params.stuid)
						.replace(':type', this.$route.params.type),
				};
			});
			return bread;
		},
	},
	mounted() {
		this.getOpeartion();
	},
	methods: {
		// 获取面包屑名称
		getOpeartion() {
			this.loading = true;
			this.GetOperationList().then((rst) => {
				this.loading = false;
				if (rst.code === 1) {
					this.firstRoter = rst.firstRoter;
					this.secondRouter = rst.secondRouter;
				} else {
					this.$message.error(rst.msg);
				}
			});
		},
		processBread(name) {
			let names = '';
			switch (name) {
				case 'examList':
					return `${this.firstRoter}${this.batchTitle ? '：' + this.batchTitle : this.batchTitle}`;
				case 'examManagement':
					return `${this.secondRouter}${this.examTitle ? '：' + this.examTitle : this.examTitle}`;
				case 'approvalManagement':
					return `${this.firstRoter}${this.examTitle ? '：' + this.examTitle : this.examTitle}`;
				case 'questionManagement':
					return `${this.firstRoter}${this.courseTitle ? '：' + this.courseTitle : this.courseTitle}`;
				case 'proctorTeacher':
					return `${this.breadNameList[name]}${this.teacherName ? '：' + this.teacherName : this.teacherName}`;
				case 'memManagement':
					names = '';
					if (this.roleId == localStorage.getItem('RoleId')) {
						names = localStorage.getItem('RoleName');
					} else {
						this.$router.push({
							name: 'roleManagement',
						});
					}
					return `${this.secondRouter}(${names})`;
				case 'carteManagement':
					names = '';
					if (this.roleId == localStorage.getItem('RoleId')) {
						names = localStorage.getItem('RoleName');
					} else {
						this.$router.push({
							name: 'roleManagement',
						});
					}
					return `${this.secondRouter}(${names})`;
				case 'addQuestion':
					return this.secondRouter;
				case 'schoolManagement':
					return this.firstRoter;
				case 'facultyManagement':
					return this.firstRoter;
				case 'majorManagement':
					return this.firstRoter;
				case 'gradeManagement':
					return this.firstRoter;
				case 'classManagement':
					return this.firstRoter;
				case 'teacherManagement':
					return this.firstRoter;
				case 'studentManagement':
					return this.firstRoter;
				case 'menuRole':
					return this.firstRoter;
				case 'roleManagement':
					return this.firstRoter;
				case 'recycleBin':
					return this.firstRoter;
				case 'categoryManagement':
					return this.firstRoter;
				case 'examRoomManagement':
					return this.firstRoter;
				case 'ruleManage':
					return this.firstRoter;
				case 'todayExam':
					return this.firstRoter;
				case 'invigilateManagement':
					return this.firstRoter;
				default:
					return this.breadNameList[name];
			}
		},
		// 传递选择的id
		handleChange(val) {
			this.$emit('getPaperIndex', val);
			this.$parent.changeReviewPaper && this.$parent.changeReviewPaper(val);
		},
		backAction() {
			console.log(this.breadNewList[this.breadNewList.length - 2].path);
			this.$router.push(this.breadNewList[this.breadNewList.length - 2].path).catch((error) => {
				//去除路由报错提示
			});
		},
	},
};
</script>
